package HomeWork.set;

import java.text.Collator;
import java.util.Collections;
import java.util.Locale;
import java.util.TreeSet;

public class Test2 {
    public static void main(String[] args) {
        TreeSet<Student> students = new TreeSet<>();
        Collections.addAll(students,
                new Student("韩金龙", 88, 88.5, 90),
                new Student("卢本伟", 83, 91, 91),
                new Student("刘谋", 87, 73, 87),
                new Student("周淑怡", 88, 88.5, 90),
                new Student("小团团", 90, 94, 98)
        );
        System.out.println(students);
    }
}

class Student implements Comparable<Student>{
    private String name;
    private double chineseScore;
    private double mathScore;
    private double englishScore;

    public Student() {
    }

    public Student(String name, double chineseScore, double mathScore, double englishScore) {
        this.name = name;
        this.chineseScore = chineseScore;
        this.mathScore = mathScore;
        this.englishScore = englishScore;
    }

    @Override
    public int compareTo(Student o) {
        double result = this.chineseScore - o.chineseScore;
        result = result == 0 ? this.mathScore - o.mathScore : result;
        result = result == 0 ? this.englishScore - o.englishScore : result;
        result = result == 0 ? Collator.getInstance(Locale.CHINA).compare(this.name,o.name) : result;
        int ans = result > 0 ? 1 : 0;
        ans = result < 0 ? -1 : ans;
        return ans;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return chineseScore
     */
    public double getChineseScore() {
        return chineseScore;
    }

    /**
     * 设置
     * @param chineseScore
     */
    public void setChineseScore(double chineseScore) {
        this.chineseScore = chineseScore;
    }

    /**
     * 获取
     * @return mathScore
     */
    public double getMathScore() {
        return mathScore;
    }

    /**
     * 设置
     * @param mathScore
     */
    public void setMathScore(double mathScore) {
        this.mathScore = mathScore;
    }

    /**
     * 获取
     * @return englishScore
     */
    public double getEnglishScore() {
        return englishScore;
    }

    /**
     * 设置
     * @param englishScore
     */
    public void setEnglishScore(double englishScore) {
        this.englishScore = englishScore;
    }

    public String toString() {
        return "姓名 = " + name + ", 语文成绩 = " + chineseScore + ", 数学成绩 = " + mathScore + ", 英语成绩 = " + englishScore + "\n";
    }
}
